/*
 * 用户列表
 */
define(function(require, exports, module) {
    require("common/umei.dev");
    // var page = require("common/umei.pagination");
    // var ajax = require("common/umei.ajax");
    // var umei_dialog = require("common/umei.dialog");

    $("#selectAllbtn").click(function() {
	if ($(this).is(":checked")) {
	    $("#pager_content tr td input[name='chkall']").prop("checked", true);
	} else {
	    $("#pager_content tr td input[name='chkall']").prop("checked", false);
	}
    });

    $("#del-btn").click(function() {
	var checkInputs = $("#pager_content tr td input[name='chkall']:checked");
	var idsArray = [];
	for (var i = 0, _len = checkInputs.length; i < _len; i++) {
	    idsArray.push(checkInputs.eq(i).val());
	}
	if (idsArray.length == 0) {
	    umei.tipMsg({
		type : "warn", content : "请选择要删除的选项", timeout : 3000
	    });
	    return;
	}
	umei.confirm("确定要删除吗？", function() {
	    var data = {
		ids : idsArray.join(",")
	    }
	    umei.postRequest({
		async : true, url : "delRole.do", data : data, fun : function(response) {
		    initPage(umei.pageNo);
		    umei_dialog.tipMsg({
			type : "success", content : "删除成功", timeout : 1500
		    });
		}
	    });
	});
    });

    initPage(1);
    function initPage(pageNo) {
	umei.pageNo = pageNo;
	var data = {
	    pageNo : pageNo
	};
	umei.postRequest({
	    async : true,
	    url : "loadRoleList.do",
	    data : data,
	    fun : function(response) {
		var data = response.data;
		var simplePage = data.page;
		var list = data.list;
		$("#pager_content tr:gt(0)").remove();
		if (list.length > 0) {
		    for (var i = 0, _len = list.length, d; i < _len, d = list[i]; i++) {
			var edit = "";
			if (d.status.type == 0 && umei.op.showEdit == "true") {
			    edit = '<a href="role_2update.do?roleId=' + d.id + '" title="修改"><i class="icon i-edit"></i></a>';
			}
			var showDetail = "";
			if (umei.op.showDetail == "true") {
			    showDetail = '<a href="role_showRole.do?roleId=' + d.id + '" title="查看"><i class="icon i-preview"></i></a>';
			}
			$(
				'<tr><td valign="center"><input name="chkall"  type="checkbox" value=' + d.id + '></td><td>' + d.roleName + '</td><td>' + showDetail + '</td><td>'
					+ d.status.description + '</td><td>' + edit + '</td></tr>').appendTo($("#pager_content"));
		    }
		} else {
		    $('<tr><td  class="nodata" colspan="100">没有数据</td></tr>').appendTo($("#pager_content"));
		}
		umei.pagination({
		    pagePanelId : "pager", pageObj : simplePage, fun : initPage
		});
	    }
	});
    }
});
